package api

import (
	"fmt"
	"net/http"

	"gitee.com/h2ob/facada"
	h2of "gitee.com/h2ob/h2of/base"
	"github.com/gin-gonic/gin"
)

func planItEarth(c *gin.Context) {
	req := facada.H2oAiTravelReq{}
	if err := c.BindJSON(&req); err != nil {
		h2of.GLogger.Infoln("Can not find args:%s", err)
		c.String(http.StatusBadRequest, "Can not find args")
		return
	}

	id, err := beginItineraryGen()
	if err != nil {
		c.String(http.StatusInternalServerError, "Call failed")
		return
	}
	rsp, err := doGenItinerary(id, &req)
	if err != nil {
		c.String(http.StatusInternalServerError, "Call failed")
		return
	}
	hRsp := facada.H2oRsp{TID: req.TID, Code: http.StatusOK, Msg: "OK", Data: rsp}
	c.JSON(http.StatusOK, &hRsp)
}

func RegisterApi(prefix string, router *gin.Engine, jwtHandler gin.HandlerFunc) {
	apiv1 := router.Group(fmt.Sprintf("%s/api/v1", prefix))
	{
		apiv1.POST("/aifuns/gen-travel", planItEarth)
	}
}
